package com.woniu.adapter;

import com.woniu.outlet.mysql.UserDetailDao;
import com.woniu.outlet.mysql.po.UserDetailMySQL;
import com.woniu.service.domain.UserDetail;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserDetailAdapter {

    @Autowired
    private UserDetailDao userDetailDao;

    /**
     * 根据userid获取用户信息
     * @return
     */
    public UserDetail getUserById(Integer userId){
        UserDetailMySQL userDetailSQL = userDetailDao.selectByUserId(userId);
        UserDetail userDetail = new UserDetail();
        BeanUtils.copyProperties(userDetailSQL,userDetail);
        return userDetail;
    }

    /**
     * 修改用户信息
     * @param userDetail
     */
    public void updateInfo(UserDetail userDetail){
        UserDetailMySQL userDetailSQL = new UserDetailMySQL();
        BeanUtils.copyProperties(userDetail,userDetailSQL);
        userDetailDao.updateByUserId(userDetailSQL);
    }

    /**
     * 添加新注册的用户
     */
    public void addUser(UserDetail userDetail){
        UserDetailMySQL userDetailMySQL = new UserDetailMySQL();
        BeanUtils.copyProperties(userDetail,userDetailMySQL);
        userDetailDao.insertSelective(userDetailMySQL);
    }
}
